package org.jtzc.springaimcpclient.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class LLMMcpController {
    @Autowired
    private ChatClient chatClient;


    /**
     * 先访问 http://127.0.0.1:8081/simple/chat?query=你是谁
     * 再访问 http://127.0.0.1:8081/simple/chat?query=明天星期几
     * 查看server端日志情况
     * @param query
     * @return
     */
//    @GetMapping("/simple/chat")
//    public Flux<String> simpleChat(@RequestParam(value = "query", defaultValue = "10分钟后，设置一个闹铃。")String query) {
////        return chatClient.prompt(query).call().content();
////        return "ok";
//        AssistantMessage output = chatClient.prompt(query)
//                .call()
//                .chatResponse()
//                .getResult().getOutput();
//        return output.getText();
//
//    }

    @GetMapping(value = "/chatStream", produces = "text/html;charSet=utf-8")
    public Flux<String> stream(@RequestParam(value = "query", defaultValue = "10分钟后，设置一个闹铃。")String query) {
        return chatClient.prompt().user(query).stream().content();
    }
}
